﻿using System.Collections.Generic;
using System.Linq;
using DataBaseLayer.Dto;
using Peresvet.Models;

namespace Peresvet.Extensions
{
	public static class NewsItemModelEx
	{
		public static NewsItemModel ConvertNewsDataItemToMVCModel(this NewsData data)
		{
			if (data == null) return null;

			return new NewsItemModel
			{
				Date = data.Date,
				Description = data.Description,
				GalleryId = data.GalleryId,
				Header = data.Header,
				ImageUrl = data.ImageUrl,
				NewsId = data.NewsId,
				ThumbImageUrl = data.ThumbImageUrl
			};
		}

		public static IEnumerable<NewsItemModel> ConvertNewsDataItemsToMVCModel(this IEnumerable<NewsData> data)
		{
			if (data == null && data.Any()) return null;

			return data.Select(item => item.ConvertNewsDataItemToMVCModel()).ToList();
		}
	}
}